<?php

namespace App\Http\Controllers\Front;

use App\Model\FrontLog;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class FrontLogController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function addLog(Request $request)
    {

        $frontLog = new FrontLog;
        $frontLog->type = $request->input("type");
        $frontLog->name = $request->input("name");
        $frontLog->script = $request->input("script");
        $frontLog->line = $request->input("line");
        $frontLog->column = $request->input("column");
        $frontLog->stack = $request->input("stack");
        $frontLog->save();
        return $this->success();
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function getLog(Request $request)
    {
        $query = FrontLog::orderBy("created_at", "desc");

        if ($start_update = $request->query('start_update_time')){
            $query = $query->where('created_at',  '>=', $start_update);
        }

        if ($end_update = $request->query('end_update_time')){
            $query = $query->where('created_at',  '>=', $end_update);
        }
        $items = $query->paginate(10);

        return $this->renderJson ($items);
    }


}
